﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QLHD.BLL;
using System.Data;
using System.Data.SqlClient;

namespace QLHD.DAL
{
    public class PhanLoai_DB
    {
        public static DataTable SelectAll()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from tblCT_PhanLoai", con);
                con.Open();
                SqlCommand command = new SqlCommand("select * from tblCT_PhanLoai", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static void Insert(PhanLoai item)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spThemCTPhanLoai", con);
                con.Open();
                SqlCommand cmd = new SqlCommand("spThemCTPhanLoai", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@MaCT_PhanLoai", item.MaCT_PL);
                cmd.Parameters.AddWithValue("@Ngaythang", item.Ngaythang);
                cmd.Parameters.AddWithValue("@MaNX", item.MaNX);
                cmd.Parameters.AddWithValue("@MaLo", item.MaLo);
                cmd.Parameters.AddWithValue("@MaTP", item.MaTP);
                cmd.Parameters.AddWithValue("@DienGiai", item.DienGiai);
                cmd.Parameters.AddWithValue("@KL_NhapPL", item.KL_NhapPL);
                cmd.Parameters.AddWithValue("@KL_XuatTP", item.KL_XuatTP);

                cmd.ExecuteNonQuery();
            }
        }
        public static void Update(string oldMaCT_PL,PhanLoai item )
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spCapNhatCTPhanLoai", con);
                con.Open();
                SqlCommand cmd = new SqlCommand("spCapNhatCTPhanLoai", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@MaCT_PhanLoai", item.MaCT_PL);
                cmd.Parameters.AddWithValue("@Ngaythang", item.Ngaythang);
                cmd.Parameters.AddWithValue("@MaNX", item.MaNX);
                cmd.Parameters.AddWithValue("@MaLo", item.MaLo);
                cmd.Parameters.AddWithValue("@MaTP", item.MaTP);
                cmd.Parameters.AddWithValue("@DienGiai", item.DienGiai);
                cmd.Parameters.AddWithValue("@KL_NhapPL", item.KL_NhapPL);
                cmd.Parameters.AddWithValue("@KL_XuatTP", item.KL_XuatTP);
          
                cmd.ExecuteNonQuery();
            }
        }
        public static void Delete(string MaCT_PL)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spXoaCTPhanLoai", con);
                con.Open();
                SqlCommand cmd = new SqlCommand("spXoaCTPhanLoai", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@MaCT_PhanLoai", MaCT_PL);
                cmd.ExecuteNonQuery();
            }



        }
    }
}
